package de.fhwf.mixedreality.client2007;

class CommandInterface {
 private String mCmd;
 private String mLastCmd;
 
 public CommandInterface() {
  mCmd = "";
  mLastCmd = "";
 }

 /** Command to set velocity */
 void setVelocity(int leftWheel, int rightWheel) {
  mCmd = vel2Str(leftWheel) + vel2Str(rightWheel);
 }

 /** Setup a kick command */
 void setKick(double angle, double strength) {
	 
  mCmd = String.format("KICK %3.3f %3.3f", angle, strength); 
  mCmd = mCmd.replace(',', '.');
//  System.out.println(mCmd);
 }

 /** Set a raw command */
 void setRaw(String cmd) { 
  mCmd = cmd;
 }
 
 void setMMPS(int left, int right){
  mCmd  = Integer.toString(left) +"," +  Integer.toString(right);
 }
 
 /**
  * Returns the string with the command.
  * If no command was set string will be empty.
  * After this the command is eliminated
  * from memory.
  */
 String getCmd() {
  mLastCmd = mCmd;
  mCmd = "";
  return mLastCmd;
 }

 String getLastCmd() {
  return mLastCmd;
 }

 private String vel2Str(int vel) {
  String code = "ST";
  switch (vel) {
   case -4:
    code = "BN";
    break;
   case -3:
    code = "BF";
    break;
   case -2:
    code = "BM";
    break;
   case -1:
    code = "BS";
    break;
   case 1:
    code = "FS";
    break;
   case 2:
    code = "FM";
    break;
   case 3:
    code = "FF";
    break;
   case 4:
    code = "FN";
    break;
  }
  return code;
 }
}